<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>日报</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/t_style.css"/>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/main.js"></script>
    <script src="../../js/jquery.flexText.min.js"></script>
</head>
<body>
<div id="app">
    <header class="mui-bar mui-bar-nav">
        <span class="back" @click="back"></span>
        <span class="cross" @click="close"></span>
        <h1 class="mui-title" style="left: 80px;right: 80px">日报</h1>
    </header>
    <div class="mui-content" style="padding-bottom: 70px">
        <div class="module-area">
            <div class="module">
                <p>今日工作总结</p>
                <div class="write-area">
                    <textarea placeholder="请输入文字" v-model="summarize"></textarea>
                </div>
            </div>
            <div class="module">
                <p>未完成的工作</p>
                <div class="write-area">
                    <textarea placeholder="请输入文字" v-model="not_finish"></textarea>
                </div>
            </div>
            <div class="module">
                <p>明日工作计划</p>
                <div class="write-area">
                    <textarea placeholder="请输入文字" v-model="plan"></textarea>
                </div>
            </div>
            <div class="module">
                <p>体会与建议</p>
                <div class="write-area">
                    <textarea placeholder="请输入文字" v-model="experience"></textarea>
                </div>
            </div>
            <div class="module">
                <p>备注</p>
                <div class="write-area">
                    <textarea placeholder="请填写备注" v-model="remark"></textarea>
                </div>
            </div>
        </div>
        <!--<div class="add-sender sender-group">
            <p style="margin-bottom: 5px">添加群<span>（点击可删除）</span></p>
            <span class="report-group" v-show="group" v-for="(item,index) in group_name" v-text="item.groupName" @click="del_group(index)" style="margin-right: 10px"></span><div class="add-btn" @click="open_popup"></div>
        </div>-->
        <div class="report-footer">
            <div class="submit-btn" @click="submit">提交日报</div>
        </div>
    </div>
    <!--<div class="pop-up-bg" v-show="popup">
        <div class="pop-up">
            <div class="pop-up-top">
                <div class="pop-up-close fr" @click="close_popup">
                    <img src="../../images/cross37.png"/>
                </div>
                <div class="pop-up-title">选择发送群</div>
            </div>
            <ul class="pop-up-content">
                <li v-for="(item,index) in groups" @click="select_group(index)">
                    <div class="report-top">
                        <div class="report-headimg fl" v-text="item.hName"></div>
                        <div class="report-info">
                            <p v-text="item.name"></p>
                        </div>
                    </div>
                </li>
            </ul>
            <div class="pop-up-bottom">
                <div class="pop-up-btn">
                    <button class="mui-btn mui-btn-primary" @click="close_popup">确定</button>
                </div>
            </div>
        </div>
    </div>-->
</div>
</body>
<script>
    var client_h = document.documentElement.clientHeight;
    $(window).on("resize",function(){
        var body_h =  document.body.scrollHeight;
        if(body_h < client_h){
            $(".report-footer").hide();
        }else{
            $(".report-footer").show();
        }
    });
    function sendInfoToJava(name) {
        //调用android程序中的方法，并传递参数
        javascript:WebView.showInfoFromJs(name);
    }
    var app = new Vue({
        el: "#app",
        data: function () {
            return{
                popup: false,
                summarize: "",
                not_finish: "",
                plan: "",
                experience: "",
                remark: "",
                groups: [],
                group_name: [],
                group: false
            }
        },
        methods: {
            back: function () {
                var name = "back";
                sendInfoToJava(name);
            },
            close: function () {
                var name = "close";
                sendInfoToJava(name);
            },
            open_popup: function () {
                var this_obj = this;
                this_obj.popup = true;
                var url = "/organization/group";
                var data = {
                    "companyId": localStorage.companyId, //公司ID
                    "loginName": localStorage.userName //用户的login_name
                };
                if(typeof(localStorage.companyId) == "undefined" || typeof(localStorage.userName) == "undefined"){
                    mui.toast("请重新登录");
                }else{
                    common_ajax(url,data,function (res) {
                        if(res.code < 0){
                            mui.toast(res.errorMsg);
                        }else {
                            this_obj.groups = [];
                            for (var i in res.obj) {
                                var hName = res.obj[i]['groupname'].substr(0, 1);
                                this_obj.groups.push({
                                    id: res.obj[i]['groupid'],
                                    name: res.obj[i]['groupname'],
                                    hName: hName
                                });
                            }
                        }
                    },function (res) {
                        console.log(JSON.stringify(res));
                    });
                }
            },
            close_popup: function () {
                var this_obj = this;
                this_obj.popup = false;
            },
            submit: function () {
                var this_obj = this;
                if(this_obj.summarize == ""){
                    mui.toast('请输入今日工作总结');
                }else if(this_obj.not_finish == ""){
                    mui.toast('请输入未完成的工作');
                }else if(this_obj.plan == ""){
                    mui.toast("请输入明日工作计划");
                }else if(this_obj.experience == ""){
                    mui.toast("请输入体会与建议");
                }/*else if(this_obj.group_name.length == 0){
                    mui.toast("请添加要发送的群");
                }*/else{
                    var url = "/report/zgReport";
                    var data = {
                        "companyId": localStorage.companyId,
                        "createUser": localStorage.userName,
                        "name": localStorage.fullName,
                        "sendGroupJson": "",//JSON.stringify(this_obj.group_name),
                        "sendUserIdJson": "",
                        "textList": [
                            {"content": this_obj.summarize,"title": "今日工作总结"},
                            {"content": this_obj.not_finish,"title": "未完成工作"},
                            {"content": this_obj.plan,"title": "明日工作计划"},
                            {"content": this_obj.experience,"title": "体会与建议"},
                            {"content": this_obj.remark,"title": "备注"}
                        ],
                        "type": 1 //1日报 2周报 3月报
                    };
                    if(typeof(localStorage.companyId) == "undefined" || typeof(localStorage.userName) == "undefined" || typeof(localStorage.fullName) == "undefined"){
                        mui.toast("请重新登录");
                    }else {
                        common_ajax(url, data, function (res) {
                            if (res.code < 0) {
                                mui.toast(res.errorMsg);
                            } else {
                                var name = "go";
                                sendInfoToJava(name);
                            }
                        }, function (res) {
                            mui.toast("发送失败");
                        });
                    }
                }
            },
            select_group: function (index) {
                var this_obj = this;
                this_obj.popup = false;
                this_obj.group = true;
                this_obj.group_name.push({'groupId':this_obj.groups[index]['id'],'groupName': this_obj.groups[index]['name']});
            },
            del_group: function (index) {
                var this_obj = this;
                for(var i in this_obj.group_name){
                    this_obj.group_name.splice(index,1);
                }
            }
        }
    });
    $(function () {
        $('textarea').flexText();
    });
</script>
</html>
